//路由配置
(function() {
var Service = APM.Service = createApp("service");

Service.routerMap(function() {
	//服务节点
	this.route("server",function(){
		this.route("follow");
		this.route("allserver");
		this.route("toposerver");
		this.route("nodeserver",{path:"/:node_id"},function(){
			//服务概况
			this.route("overview");
			//错误码
			this.route("errorcode");
			//最新告警
			this.route("alarms");
			//动态菜单
			this.route("dynamic", {path: "/:menu_id"});
			//交易类型
			this.route("type");
			//交易渠道
			this.route("channel");
			//交易跟踪
			this.route("track");
		});
	});
});

APM.ServiceRoute = Service.Route.extend({
	templates: [
		{
			name: "main/frame",
			url: "/apps/main/tpls/main_frame.hbs"
		}
	],

	dependences: [
		"/apps/main/ctrls/frame_ctrl",
		"/apps/main/views/frame_view",
	],

	renderTemplate: function(){
		this.render("main/frame", {controller: "mainFrame", view: "mainFrame"});
	}
});

APM.ServiceIndexRoute = Service.Route.extend({
	redirect : function() {
		this.transitionTo("service.server");
	}
});

/*---------路由定义----------- */
//服务节点
APM.ServiceServerRoute = Service.Route.extend({
	dependences : [
		"./ctrls/server_ctrl",
		"./views/server_view",
		"./ctrls/allserver_ctrl"
	],
	model:function(){
		return this.store.ajax("GET","nodes/serviceFocusCount")
		.then(function(response){
			var serviceFocusCount = Ember.A(response.serviceFocusCount);
			return serviceFocusCount;
		});
	},
	setupController: function(ctrl, model, transition){
		ctrl.set("serviceFocus",model.serviceFocus);
		ctrl.set("serviceAll",model.serviceAll);
	}
});

//服务节点--关注服务
APM.ServiceServerFollowRoute = Service.Route.extend({
	dependences : [
		"./ctrls/follow_ctrl",
		"./views/follow_view"
	],
	model:function(){
		return this.store.ajax("GET","alarms/serviceCount")
		.then(function(response){
			var serRankNums = Ember.A(response.serRankNums);
				return serRankNums;
		});
	},
	setupController: function(ctrl, model, transition){
		ctrl.set("serRankNums",model);
		ctrl.getserviceType();
	    ctrl.set("serviceValue","");
	},
	deactivate: function(){
		this.controller.clearserverity();
	}
});

//服务节点--全部服务
APM.ServiceServerAllserverRoute = Service.Route.extend({
	dependences : [
		"./ctrls/allserver_ctrl",
		"./views/allserver_view"
	],
	model:function(){
		return this.store.ajax("GET","nodes/serviceFocusCount")
		.then(function(response){
			var serviceFocusCount = Ember.A(response.serviceFocusCount);
			return serviceFocusCount;
		});
	},
	setupController: function(ctrl, model, transition){
		ctrl.set("serviceFocus",model.serviceFocus);
		ctrl.set("serviceAll",model.serviceAll);
		 ctrl.set("serviceValue","");
		ctrl.allServerResponse();
		ctrl.getserviceType();
	}
});

//服务节点--服务拓扑图
APM.ServiceServerToposerverRoute = Service.Route.extend({
	dependences : [
		"./ctrls/toposerver_ctrl.js?111",
		"./views/toposerver_view"
	],
	model:function(){
		return this.store.ajax("GET","topology/services")
		.then(function(response){
			return response;
		});
	},
	setupController: function(ctrl, model, transition){
		ctrl.topoServerRender(model);
	}
});

//服务节点--详情节点
APM.ServiceServerNodeserverRoute = Service.Route.extend({
	dependences : [
		"./ctrls/nodeserver_ctrl",
		"./views/nodeserver_view"
	],
	model:function(params){
		return this.store.ajax("GET", "nodes/disService",{"serviceId":params.node_id})
		.then(function(response){
			var nodes = Ember.A(response.node);
			return nodes;
		});
	}
});

APM.ServiceServerNodeserverIndexRoute = Service.Route.extend({
	redirect: function() {
		this.transitionTo("service.server.nodeserver.overview");
	}
});


//节点详情-服务概况
APM.ServiceServerNodeserverOverviewRoute =  Service.Route.extend({
	dependences: [
		"./ctrls/nodeserver_overview_ctrl",
		"./views/nodeserver_overview_view"
	],
	setupController: function(ctrl, model, transition){
		ctrl.startRealTimeMode();
		ctrl.setup(model);
	},
	deactivate: function(){
		this.controller.stopRealTimeMode();
	}
});

//节点详情-服务告警
APM.ServiceServerNodeserverAlarmsRoute =  Service.Route.extend({
	dependences: [
		"./ctrls/nodeserver_alarms_ctrl",
		"./views/nodeserver_alarms_view"
	]
});

//节点详情-服务错误
APM.ServiceServerNodeserverErrorcodeRoute =  Service.Route.extend({
	dependences: [
		"./ctrls/nodeserver_errorcode_ctrl",
		"./views/nodeserver_errorcode_view"
	]
})

//节点详情-交易类型
APM.ServiceServerNodeserverTypeRoute = Service.Route.extend({
	dependences: [
		"./ctrls/nodeserver_type_ctrl",
		"./views/nodeserver_type_view"
	]
});

//节点详情-交易渠道
APM.ServiceServerNodeserverChannelRoute = Service.Route.extend({
	dependences: [
		"./ctrls/nodeserver_channel_ctrl",
		"./views/nodeserver_channel_view"
	]
});

//节点详情-交易跟踪
APM.ServiceServerNodeserverTrackRoute = Service.Route.extend({
	dependences: [
		"./ctrls/nodeserver_track_ctrl",
		"./views/nodeserver_track_view"
	]
});

//动态菜单
APM.ServiceServerNodeserverDynamicRoute = Service.Route.extend({
	dependences: [
		"./ctrls/nodeserver_dynamic_ctrl",
		"./views/nodeserver_dynamic_view"
	],
	model: function(params, transition){

		return this.store.ajax("GET", "node/menus", {
			nodeId: transition.resolvedModels["service.server.nodeserver"].id
		})
		.then(function(response){
			var menu = Ember.A(response.result).findBy("id", parseInt(params.menu_id));
			return menu;
			// if(menu){
				
			// }else{
			// 	transition.abort();
			// 	this.transitionTo("service.server.nodeserver.overview");
			// }
		});
	}
});

})();